<?php
/**
 * 处理数据逻辑
 */

namespace common\helpers;

use Yii;


class QueryHelper
{
    /**
     * 分割参数
     * @param $str
     * @param string $delimiter
     * @return array
     */
    public static function splitQueryString($str, $delimiter = '-') {
        if(empty($str)) {
            return array();
        }
        $list = explode($delimiter, $str);
        $result = array();
        $len = count($list);
        if($len%2 !== 0) {
            Yii::$app->getLog()->getLogger()->log('ERROR Query String :' . $str, yii\log\Logger::LEVEL_ERROR);
            return [];
        }
        for($i = 0; $i < $len; $i+=2){
            $result[$list[$i]] = $list[$i + 1];
        }
        return $result;
    }
    
}